//
//  RecommendDetailViewController.m
//  Happy Kitchen
//
//  Created by mac_chen on 15/3/7.
//  Copyright (c) 2015年 mac_chen. All rights reserved.
//

#import "RecommendDetailViewController.h"

@interface RecommendDetailViewController ()

@end

@implementation RecommendDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    self.navigationItem.title = self.name;
    
    self.recommendDetailScorll = [[RecommendDetailScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    //设置contentsize
    self.recommendDetailScorll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 4);
    [self.view addSubview:self.recommendDetailScorll];
    
    
    //菊花
    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:self.HUD];
    self.HUD.labelText = @"加载中";
    [self.HUD showAnimated:YES whileExecutingBlock:^{
        
        NSLog(@"%@", @"加载中...");
        [self maxTime];
        
    } completionBlock:^{
        
        
    }];
    
    
    
    
    

    //初始化
    //接收制作步骤的数组,字典
    self.myArray = [NSMutableArray array];
    self.myDic = [NSMutableDictionary dictionary];
    
    //接收制作材料的数组,字典
    self.arr = [NSMutableArray array];
    self.dic = [NSMutableDictionary dictionary];

    
    NSString *str1 = [NSString stringWithFormat:@"http://42.121.13.106:8080/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?&phonetype=2&user_id=101713&is_traditional=0&"];
    NSString *str2 = [NSString stringWithFormat:@"vegetable_id=%@", self.vegetable_id];
    NSString *urlStr = [str1 stringByAppendingString:str2];
    
    
    
    
    [GetAFN downLoadBlock:urlStr block:^(id result) {
        self.dic = result;
        NSMutableArray *array = [NSMutableArray arrayWithArray:[self.dic objectForKey:@"data"]];
        //        NSLog(@"array  =  %@" ,array);
        
        for (NSDictionary *dictionary in array) {
            
            RecommendDetailModel *recommendDetail = [[RecommendDetailModel alloc] init];
            
            
            
            [recommendDetail setValuesForKeysWithDictionary:dictionary];
            
            
//            NSLog(@"%@ %@", recommendDetail.name, recommendDetail.fittingRestriction);
            //调用model页面的自定义赋值方法
                        [self.recommendDetailScorll createSub:self.myArray recommendDetail:recommendDetail];
            
            [self.arr addObject:recommendDetail];
            [self.recommendDetailScorll setRecommendDetail:recommendDetail];

            
            
        }
        
        [self getReCommDetail];


    }];
    
}

//自定义方法,请求制作材料的数据

-(void)getReCommDetail{
    //拼接制作步骤的字符串
    NSString *str3 = @"http://42.121.13.106:8080/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?&type=2&phonetype=0&is_traditional=0&";
    NSString *str4 = [NSString stringWithFormat:@"vegetable_id=%@",self.vegetable_id];
    NSString *str = [str3 stringByAppendingString:str4];
    
    NSLog(@"%@", str);
    
    [GetAFN downLoadBlock:str block:^(id result) {
        
        self.myDic = result;
        NSMutableArray *array = [NSMutableArray arrayWithArray:[self.myDic objectForKey:@"data"]];
        
        for (NSDictionary *dic in array) {
            RecommendDetailModel *recommendDetail = [[RecommendDetailModel alloc] init];
            
            //kvc赋值
            [recommendDetail setValuesForKeysWithDictionary:dic];
            
            //数据放入数组中
            [self.myArray addObject:recommendDetail];
            
        }
        
        [self.recommendDetailScorll stepCookarray:self.myArray recommendDetail:nil];
        
                [self.HUD removeFromSuperview];
    }];

}

//刷新时间上限
- (void)maxTime
{
    sleep(10);
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
